package com.base.home.adapter;

import android.databinding.DataBindingUtil;
import android.view.View;

import com.alibaba.android.arouter.launcher.ARouter;
import com.base.commonlib.recy.BasicRecyViewHolder;
import com.base.commonlib.recy.HFSingleTypeRecyAdapter;
import com.base.home.R;
import com.base.home.bean.ConcertSelectEntity;
import com.base.home.databinding.ItemCoursewareBinding;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;

/**
 * 在此写用途
 *
 * @version V1.0 <描述当前版本功能>
 *          Created by admin on 2018/5/22.
 * @FileName: com.zhongyue.mdchengguan.ui.main.adapter.CategoryAdapter.java
 * Author weikailiang
 * @date: 2018-05-22 17:31
 */
public class CourseAdapter extends HFSingleTypeRecyAdapter<ConcertSelectEntity.RecentLearnBean,CourseAdapter.RecyViewHolder> {


    public CourseAdapter(int resId) {
        super(resId);
    }

    @Override
    public RecyViewHolder buildViewHolder(View itemView) {
        return new RecyViewHolder(itemView);
    }

    @Override
    public void bindDataToHolder(RecyViewHolder holder, final ConcertSelectEntity.RecentLearnBean bean, int position) {
       holder.mBinding.courseTitle.setText(bean.getName());
       holder.mBinding.courseIntro.setText(bean.getCreateUserName()==null?"":"作者:"+bean.getCreateUserName());
       holder.mBinding.courseTime.setText(bean.getCreateDate());
        Glide.with(holder.mBinding.coursePhoto.getContext())
                .load(bean.getCover())
                .apply(new RequestOptions().error(R.drawable.ic_empty)
                        .placeholder(R.drawable.ic_empty)
                        .diskCacheStrategy(DiskCacheStrategy.RESOURCE))
                .into(holder.mBinding.coursePhoto);
        holder.mBinding.courseCardview.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ARouter.getInstance().build("/curriculum/detail").withString("id",bean.getId())
                        .withString("url",bean.getCover()).navigation();
            }
        });
    }

    public static class RecyViewHolder extends BasicRecyViewHolder {
        private ItemCoursewareBinding mBinding;
        public RecyViewHolder(View itemView) {
            super(itemView);
            mBinding = DataBindingUtil.bind(itemView);
        }
    }
}
